package com.ruoyi.project.modules.interfaceModel.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.modules.interfaceModel.domain.InterfaceModel;
import com.ruoyi.project.modules.interfaceModel.service.IInterfaceModelService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 接口模式统计Controller
 *
 * @author smallrain
 * @date 2022-06-11
 */
@Controller
@RequestMapping("/interfaceModel/interfaceModel")
public class InterfaceModelController extends BaseController {
    private String prefix = "interfaceModel/interfaceModel";

    @Autowired
    private IInterfaceModelService interfaceModelService;

    @RequiresPermissions("interfaceModel:interfaceModel:view")
    @GetMapping()
    public String interfaceModel() {
        return prefix + "/interfaceModel";
    }

    /**
     * 查询接口模式统计列表
     */
    @RequiresPermissions("interfaceModel:interfaceModel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(InterfaceModel interfaceModel) {
        startPage();
        List<InterfaceModel> list = interfaceModelService.selectInterfaceModelList(interfaceModel);
        return getDataTable(list);
    }

    /**
     * 导出接口模式统计列表
     */
    @RequiresPermissions("interfaceModel:interfaceModel:export")
    @Log(title = "接口模式统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(InterfaceModel interfaceModel) {
        List<InterfaceModel> list = interfaceModelService.selectInterfaceModelList(interfaceModel);
        ExcelUtil<InterfaceModel> util = new ExcelUtil<InterfaceModel>(InterfaceModel.class);
        return util.exportExcel(list, "接口模式统计数据");
    }

    /**
     * 新增接口模式统计
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存接口模式统计
     */
    @RequiresPermissions("interfaceModel:interfaceModel:add")
    @Log(title = "接口模式统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(InterfaceModel interfaceModel) {
        return toAjax(interfaceModelService.insertInterfaceModel(interfaceModel));
    }

    /**
     * 修改接口模式统计
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        InterfaceModel interfaceModel = interfaceModelService.selectInterfaceModelById(id);
        mmap.put("interfaceModel", interfaceModel);
        return prefix + "/edit";
    }

    /**
     * 修改保存接口模式统计
     */
    @RequiresPermissions("interfaceModel:interfaceModel:edit")
    @Log(title = "接口模式统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InterfaceModel interfaceModel) {
        return toAjax(interfaceModelService.updateInterfaceModel(interfaceModel));
    }

    /**
     * 删除接口模式统计
     */
    @RequiresPermissions("interfaceModel:interfaceModel:remove")
    @Log(title = "接口模式统计", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(interfaceModelService.deleteInterfaceModelByIds(ids));
    }

    @GetMapping("/refresh")
    @ResponseBody
    public AjaxResult refresh() {
        this.interfaceModelService.refresh();
        return AjaxResult.success();
    }
}